package com.hua.Thread.ThreadPool;

import javax.swing.plaf.TableHeaderUI;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author: _hua
 * @created: 2019/3/10.
 * @updater:
 * @description:
 */
public class SimpleThreadPool {

    public static void main(String[] args) {
        final CountDownLatch latch = new  CountDownLatch(10);
        ExecutorService executor = Executors.newFixedThreadPool(5);
        for (int i = 0; i < 10; i++) {
            Runnable worker = new WorkerThread("" + i,latch);
            executor.execute(worker);
        }
        executor.shutdown();
        try {
            latch.await();//主线程等待，其他线程执行完 执行countdown
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        //自循环
     /*   while (!executor.isTerminated()) {

        }*/
     //主线程挂起
        /*try {
            Thread.currentThread().join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }*/

        System.out.println("Finished all threads");
    }

}